package feign;

import feign.Request.HttpMethod;

import java.util.Date;

public class RetryableException extends FeignException {

    private static final long serialVersionUID = 1L;

    private final Long retryAfter;
    private final HttpMethod httpMethod;

    public RetryableException(int status, String message, HttpMethod httpMethod, Throwable cause, Date retryAfter, Request request) {
        super(status, message, request, cause);
        this.httpMethod = httpMethod;
        this.retryAfter = retryAfter != null ? retryAfter.getTime() : null;
    }

    public RetryableException(int status, String message, HttpMethod httpMethod, Date retryAfter, Request request) {
        super(status, message, request);
        this.httpMethod = httpMethod;
        this.retryAfter = retryAfter != null ? retryAfter.getTime() : null;
    }

    public Date retryAfter() {
        return retryAfter != null ? new Date(retryAfter) : null;
    }

    public HttpMethod method() {
        return this.httpMethod;
    }
}
